package cn.iocoder.yudao.module.handguard.service.userbasetable13;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable13.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable13.UserBaseTable13DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable13.UserBaseTable13Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable13.UserBaseTable13Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 企业发票贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable13ServiceImpl implements UserBaseTable13Service {

    @Resource
    private UserBaseTable13Mapper userBaseTable13Mapper;

    @Override
    public Long createUserBaseTable13(UserBaseTable13CreateReqVO createReqVO) {
        // 插入
        UserBaseTable13DO userBaseTable13 = UserBaseTable13Convert.INSTANCE.convert(createReqVO);
        userBaseTable13Mapper.insert(userBaseTable13);
        // 返回
        return userBaseTable13.getId();
    }

    @Override
    public void updateUserBaseTable13(UserBaseTable13UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable13Exists(updateReqVO.getId());
        // 更新
        UserBaseTable13DO updateObj = UserBaseTable13Convert.INSTANCE.convert(updateReqVO);
        userBaseTable13Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable13(Long id) {
        // 校验存在
        validateUserBaseTable13Exists(id);
        // 删除
        userBaseTable13Mapper.deleteById(id);
    }

    private void validateUserBaseTable13Exists(Long id) {
        if (userBaseTable13Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE13_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable13DO getUserBaseTable13(Long id) {
        LambdaQueryWrapper<UserBaseTable13DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable13DO::getApplicationId,id);
        return userBaseTable13Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable13DO> getUserBaseTable13List(Collection<Long> ids) {
        return userBaseTable13Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable13DO> getUserBaseTable13Page(UserBaseTable13PageReqVO pageReqVO) {
        return userBaseTable13Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable13DO> getUserBaseTable13List(UserBaseTable13ExportReqVO exportReqVO) {
        return userBaseTable13Mapper.selectList(exportReqVO);
    }

}
